<?php


namespace App\Common;


class Time
{
    /*获取今天开始日期和结束日期*/
    public static function today(): array
    {
        $data['start'] = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
        $data['end'] = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1;
        return $data;
    }


    /*获取昨天开始日期和结束日期*/
    public static function yesterday(): array
    {
        $data['start'] = mktime(0, 0, 0, date('m'), date('d') - 1, date('Y'));;
        $data['end'] = mktime(0, 0, 0, date('m'), date('d'), date('Y')) - 1;
        return $data;
    }

    /*获取某一天开始日期至昨天结束日期*/
    public static function nearToYesterday($day): array
    {
        $data['start'] = mktime(0, 0, 0, date('m'), date('d') - $day, date('Y'));
        $data['end'] = mktime(0, 0, 0, date('m'), date('d'), date('Y')) - 1;
        return $data;
    }

    /*把时间数组转换成时间戳*/
    public static function arrayTime($time = []): array
    {
        $data['start'] = strtotime($time[0]);
        $data['end'] = strtotime($time[1]);
        return $data;
    }
}